import type { AxiosRequestConfig, Method } from "axios";
import Http from ".";
export interface RequestConfig extends AxiosRequestConfig {
    method: Method;
    url: string;
    data?: unknown;
    withToken?: boolean;
    deepData?: boolean;
}

// 创建实例并导出请求方法
const http = new Http({
    timeout: 10000,
    // 可以添加其他默认配置
})

export function request<T = any>(config: RequestConfig): Promise<T> {
    // 创建新的配置对象，避免修改原始配置
    const requestConfig = {
        ...config,
        withToken: config.withToken ?? false,  // 默认为 false
        deepData: config.deepData ?? false     // 默认为 false
    }

    return http.request<T>(
        requestConfig.method,
        requestConfig.url,
        requestConfig.data,
        requestConfig
    )
}




